/*
 * Copyright (c) 2022-2025 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "command_info.h"
#include "avsession_errors.h"
#include "avsession_log.h"

namespace OHOS::AVSession {
CommandInfo::CommandInfo()
{
}

CommandInfo::~CommandInfo()
{
}

void CommandInfo::Unmarshalling(Parcel& data)
{
    SetCallerDeviceId(data.ReadString());
    SetCallerBundleName(data.ReadString());
    SetCallerModuleName(data.ReadString());
    SetCallerType(data.ReadString());
}

bool CommandInfo::Marshalling(Parcel& parcel) const
{
    auto WriteCommonSessionParams = [&parcel, this]() -> bool {
        return parcel.WriteString(callerDeviceId_) &&
               parcel.WriteString(callerBundleName_) &&
               parcel.WriteString(callerModuleName_) &&
               parcel.WriteString(callerType_);
    };

    CHECK_AND_RETURN_RET_LOG(WriteCommonSessionParams(), false, "write common info failed");
    return true;
}

// LCOV_EXCL_START
int32_t CommandInfo::SetCallerDeviceId(const std::string& callerDeviceId)
{
    callerDeviceId_ = callerDeviceId;
    return AVSESSION_SUCCESS;
}

int32_t CommandInfo::GetCallerDeviceId(std::string& callerDeviceId) const
{
    callerDeviceId = callerDeviceId_;
    return AVSESSION_SUCCESS;
}
// LCOV_EXCL_STOP

// LCOV_EXCL_START
int32_t CommandInfo::SetCallerBundleName(const std::string& callerBundleName)
{
    callerBundleName_ = callerBundleName;
    return AVSESSION_SUCCESS;
}

int32_t CommandInfo::GetCallerBundleName(std::string& callerBundleName) const
{
    callerBundleName = callerBundleName_;
    return AVSESSION_SUCCESS;
}
// LCOV_EXCL_STOP

// LCOV_EXCL_START
int32_t CommandInfo::SetCallerModuleName(const std::string& callerModuleName)
{
    callerModuleName_ = callerModuleName;
    return AVSESSION_SUCCESS;
}

int32_t CommandInfo::GetCallerModuleName(std::string& callerModuleName) const
{
    callerModuleName = callerModuleName_;
    return AVSESSION_SUCCESS;
}
// LCOV_EXCL_STOP

// LCOV_EXCL_START
int32_t CommandInfo::SetCallerType(const std::string& callerType)
{
    callerType_ = callerType;
    return AVSESSION_SUCCESS;
}

int32_t CommandInfo::GetCallerType(std::string& callerType) const
{
    callerType = callerType_;
    return AVSESSION_SUCCESS;
}
// LCOV_EXCL_STOP
} // namespace OHOS::AVSession
